package com.lanou.timeline.web.controller;

import com.lanou.timeline.entity.Timeline;
import com.lanou.timeline.entity.Userinfo;
import com.lanou.timeline.service.impl.TimelineServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/timeline")
public class TimelineController {
    @Autowired
    private TimelineServiceImpl timelineServiceImpl;

    /**
     * 根据碎片的分类ID查看碎片(未登录)
     */
    @GetMapping("/showtimelinebytagid")
    public List<Timeline> showByTagId(Long tagId,
                                      @RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum,
                                      @RequestParam(defaultValue = "10",value = "pageNum") Integer pageSize){
        return timelineServiceImpl.showByTagId(tagId,pageNum,pageSize);
    }
    /**
     * 根据碎片的分类ID查看碎片(登录)
     */
    @GetMapping("/showtimelinebytagidanduid")
    public List<Timeline> showByTagIdAndUid(Long tagId,Integer uid,
                                      @RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum,
                                      @RequestParam(defaultValue = "10",value = "pageNum") Integer pageSize){
        return timelineServiceImpl.showByTagIdAndUid(tagId,uid,pageNum,pageSize);
    }

    /**
     * 是否为用户喜欢的碎片
     */
    @GetMapping("/islike")
    public boolean showIsLike(String timelineId, Integer uid){
        return timelineServiceImpl.showIsLike(timelineId,uid);
    }
    /**
     *  更改喜欢碎片的状态
     */
    @PutMapping("/updateislike")
    public void updateIslike(String timelineId,Integer uid){
        timelineServiceImpl.updateIslike(timelineId,uid);
    }
    /**
     * 举报碎片
     */
    @PutMapping("/reporttimeline")
    public void reoprtTimeline(String timelineId,Integer uid){
        timelineServiceImpl.reoprtTimeline(timelineId,uid);
    }
    /**
     *  删除碎片
     */
    @DeleteMapping("/deletetimeline")
    public void deleteTimeline(String timelineId,Integer uid){
        timelineServiceImpl.deleteTimeline(timelineId,uid);
    }
    /**
     * 根据UID查看碎片
     */
    @GetMapping("/showtimelinebyuid")
    public List<Timeline> selectByUid(Integer uid){
        return timelineServiceImpl.selectByUid(uid);
    }
    /**
     * 根据碎片ID查看碎片
     */
    @GetMapping("/showtimelinebytimelineid")
    public Timeline selectByTimelineId(String timelineId){
        return timelineServiceImpl.selectByTimelineId(timelineId);
    }
    /**
     * 发布公开碎片
     */
    @PostMapping("/releasetimeline")
    public void releaseTimeline(Timeline timeline){
        timelineServiceImpl.releaseTimeline(timeline);
    }
    /**
     * 发布私密碎片
     */
    @PostMapping("/releasetimelinesecret")
    public void releaseTimelineSecret(Timeline timeline){
        timelineServiceImpl.releaseTimelineSecret(timeline);
    }

    /**
     * 相关碎片
     */
    @GetMapping("/relevanttimeline")
    public List<Timeline> relevantTimeline(){
        return timelineServiceImpl.relevantTimeline();
    }
    /**
     * 查看全部碎片(无标签)
     */
    @GetMapping("/showalltimeline")
    public List<Timeline> showAllTimeline(){
        return timelineServiceImpl.showAllTimeline();
    }

    /**
     * 查询活跃用户
     */
    @GetMapping("/selectuseractive")
    public List<Userinfo> selectUserActive(){
        return timelineServiceImpl.selectUserActive();
    }
}
